<?php
/***************
* @Project	Warabi
* @Author	Feifei
* @Date		04/10/2009
***************/

/**This module is to deal the dpf modify the default size**/
include_once($_SERVER['DOCUMENT_ROOT'].'/header.inc.php');

$httprequest = new wbHttpRequest();

list($headers , $body) = $httprequest->output();
$user_name= rawurldecode($_GET["usr"]);
$device_id = rawurldecode($_GET["dev"]);

/**if new language is empty, give a 403 response**/
$xml = simplexml_load_string($body);
if(!$xml){
	header(error_xml_structure);
	exit;
}

if($xml->device->def[0]){
	list($def_w , $def_h , $def_q)= $xml->device->def[0]->attributes();
}
if(empty($def_w)||empty($def_h)){
	header(error_xml_element_missing);
	exit;
}

/**if the sender or the device id is empty , give a 400 response**/
if(empty($user_name) || empty($device_id)){
	header(error_url_param_missing);
	exit;
}

/**if the sender doesn't exist in database , give a 400 response**/
$db = new wbDatabase();

$sql = "select id from ".__table_dpf_user__." where tel='".$user_name."' and dev = '".$device_id."' limit 1";
$set = $db->query($sql);

if($db->countResult($set)==0){
	header(error_url_param_missing);
	exit;
}


$result = $db->fetchResultBySet($set , MYSQL_ASSOC);
$dpfid = $result["id"];
$db->freeResult($set);

/** wsse authorize **/
/***if the wsse is wrong , give a 401 unauthorized response**/
$xwsse = $headers["X_WSSE"];
$type=1;
$doorkey = magicWsse($xwsse , $db , $type);

if(!$doorkey){
	header(error_autorized_header);
	exit;
}

if(empty($def_q)){
	$sql = "update ".__table_dpf_user__." set defWidth = '".$def_w."' , defHeight = '".$def_h."' where id = ".$dpfid;
}
else{
	$sql = "update ".__table_dpf_user__." set defWidth = '".$def_w."' , defHeight = '".$def_h."' , defQuality = '".$def_q."' where id = ".$dpfid;
}
$err = $db->query($sql);
$db->disconnect();
if(!$err){
	header(error_server_system);
	exit;
}


/***put the response to the client**/
header(success_response);


?>



